<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>五彩水果城</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="${base}/static/css/login.css">
	<script type="text/javascript" src="${base}/static/js/lib/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="${base}/static/js/alert.js"></script>

  </head>
  
  <body>
  	<div class="header">
  		<div class="reg-top">
  			<a href="${base}/" title="首页" alt="首页" onclick="index()"><h1>五彩水果城</h1></a>
  		</div>
  	</div>
  	<div class="section">
  		<div class="reg-content">
  			<div class="content-right">
  				<div class="reg-title">登录</div>
  				<div class="reg-form">
  					<form id="regForm" class="regForm" >
  						<label><input type="text" placeholder="请输入用户名" id="username"  class="user" onkeyup="KeyDown()"></label>
  						<label><input type="password" placeholder="请输入密码" id="password"  class="user" onkeyup="KeyDown()"></label>
  						<div class="code">
  							<input type="text" placeholder="请输入验证码" class="codeinput" id="codeinput" onkeyup="KeyDown()">
  							<img src="${base}/getcode"  onclick="this.src='${base}/getcode?d='+Math.random()"/>
  						</div><br>
  					</form>
  						<div class="submit-button">
  							<button class="submit" id="submit" onclick="login()">登录</button>
  						</div>
  						<div class="toLogin">没有账号？立即<a href="${base}/toreg">注册</a></div>
  				</div>
  				<div class="to-login"></div>
  			</div>
  		</div>
  	</div>
  	<div class="footer">
  		<div class="reg-bottom">
  			<div class="bottom-content">
  				<a href="">首页</a>
  				<a href="">合作及洽谈</a>
  				<a href="">联系我们</a>
  				<a href="">关于我们</a>
  			</div>
  			<div class="copyright">
  				<span>Copyright 2017</span>
  			</div>
  			
  		</div>
  	</div>
  	<script type="text/javascript">
  		function login(){
  			var username = $("#username").val()
  			var password = $("#password").val()
  			var code = $("#codeinput").val()
  			if(username==""){
  				layer_alert("用户名不能为空")
  				return false
  			}
  			if(password==""){
  				layer_alert("密码不能为空")
  				return false
  			}
  			if(code==""){
  				layer_alert("验证码不能为空")
  				return false
  			}
  			$.post("${base}/login",{username:username,password:password,code:code},function(data){
  				if(data.code==500){
  					layer_alert(data.msg)
  				}
  				if(data.code==200){
  					window.location.href="${base}/index";
  				}
  			});
  		}
  		function KeyDown(){
  		  if (event.keyCode == 13){
  		    event.returnValue=false;
  		    event.cancel = true;
  		    login();
  		  }
  		}
  	</script>
  </body>
</html>
